package com.cn.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.cn.entity.Reply;


public class ReplyDao {
	

	private static SessionFactory sessionFactory;
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}
	Session session;

	
	
	public List<Reply> scanAll(){
		session=sessionFactory.openSession();
		String hql="from Reply";
		Query query=session.createQuery(hql);
		List<Reply> list=query.list();
	   
	     return list;
		
		
	}
	public List<Reply> scanOne(int Messageid){
		Reply Reply=null;
		session=sessionFactory.openSession();
		String hql="from Reply where messageid=?";
		Query query=session.createQuery(hql);
		query.setInteger(0, Messageid);
		List<Reply> list=query.list();
	   
		
	     return list;
		
		
	}

	public void add(Reply Reply){
		session=sessionFactory.openSession();
		Transaction tr=session.beginTransaction();
		
		session.save(Reply);
		tr.commit();
		session.close();
		
		
		
	}
	
	public void update(Reply Reply){
		session=sessionFactory.openSession();
		Transaction tr=session.beginTransaction();
		
		session.update(Reply);
		tr.commit();
		session.close();
		
		
		
	}
	
	public void delete(Reply Reply){
		
		Transaction tr=session.beginTransaction();
		
		session.delete(Reply);
		tr.commit();
		session.close();
		
		
		
	}
	
	
}
